#include "thread_lock.h"
#include "../global/head.h"

////////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_xml
{
    thread_lock::thread_lock()
    {
        m_pLock = 0;
    }

    thread_lock::~thread_lock()
    {
        if( m_pLock )
        {
            m_pLock->release();
            m_pLock = 0;
        }
    }

    int thread_lock::un_lock()
    {
        int nRet = 0;

        if( m_pLock )
        {
            m_pLock->un_lock();
        }

        return nRet;
    }

    int thread_lock::lock()
    {
        int nRet = 0;

        if( ( 0 == nRet ) && !m_pLock )
        {
            nRet = g_pSysData->m_pXosImpl->create( xos::i_xos::XOS_OBJ_LOCK, ( void ** )&m_pLock );
        }

        if( 0 == nRet )
        {
            m_pLock->lock();
        }

        return nRet;
    }

} // xos_xml
